﻿/*****************************************************************************  

 Version: 0.1
 Website: http://www.visuagile.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate;
using Spring.Data.NHibernate.Support;

using VisualAgile.IDAL;
using VisualAgile.Model;
using Spring.Data.NHibernate;
using NHibernate.Engine;

namespace VisualAgile.DAL
{
    public class UserDao : HibernateDaoSupport, IUserDao
    {
        public User Save(User user)
        {
            HibernateTemplate.Save(user);
            return user;
        }
        public User SaveOrUpdate(User user)
        {
            HibernateTemplate.SaveOrUpdate(user);
            return user;
        }
        public void Delete(User user)
        {
            HibernateTemplate.Delete(user);
        }
        public User FindById(Guid userId)
        {            
            return HibernateTemplate.Get(typeof(User), userId) as User;
        }

        public IList FindByProject(Guid ProjectID)
        {
            return HibernateTemplate.Find("from User where ProjectID = ?", ProjectID);
        }

        public User FindByName(string UserName)
        {
            IList User = HibernateTemplate.Find("from User where UserName = ?", UserName);

            if (User.Count > 0) return User[0] as User;
            else return null;
        }

        public  IList  FindAll()
        {
            return HibernateTemplate.LoadAll(typeof (User));
        }
    }
}
